﻿@{
    ViewBag.Title = "申请人信息填写";
    var BankCardChannelId = ViewBag.BankCardChannelId;
}
@section style{

    <link href="~/Content/css/wswd.css" rel="stylesheet" />
}
<div class="proposer">
    <form action="" class="proposer_from">
        <div class="group_item">
            <label for="" class="poser_lab">姓名：</label>
            <input type="text" placeholder="" class="poser_ipt" id="name" />
        </div>
        <div class="group_item">
            <label for="" class="poser_lab">身份证号码：</label>
            <input type="text" placeholder="" class="poser_ipt" id="id_card" />
        </div>
        <div class="group_item">
            <label for="" class="poser_lab">手机号：</label>
            <input type="text" placeholder="" class="poser_ipt" id="mobile" />
        </div>
        <div class="group_item" style="border-bottom: none;">
            <a href="javascript:;" class="apply_now">提交申请</a>
        </div>
        <span class="notice_erro_1" style="font-size:14px; display: block; text-align: center; margin: 20px auto; color:red;"></span>
        <span class="notice_erro_2" style="font-size:14px; display: block; text-align: center; margin: 20px auto; color:red;"></span>
        <span class="notice_erro_3" style="font-size:14px; display: block; text-align: center; margin: 20px auto; color:red;"></span>
    </form>

</div>
<input type="text" placeholder="" class="poser_ipt" id="card_channel_id" value="@BankCardChannelId" hidden />
@section scripts{
    <script src="~/Scripts/toastr.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            // 验证中文名称
            function isChinaName(name) {
                var pattern = /[\u4e00-\u9fa5]/;
                return pattern.test(name);
            }

            // 验证手机号
            function isPhoneNo(phone) {
                var pattern = /^1[34578]\d{9}$/;
                return pattern.test(phone);
            }

            // 验证身份证
            function isCardNo(card) {
                var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                return pattern.test(card);
            }

            //判断姓名
            $("#name").blur(function () {
                if ($.trim($('#name').val()).length == 0) {
                    $(".notice_erro_1").text('名称没有输入\n');
                    $('#name').focus();

                } else {
                    if (isChinaName($.trim($('#name').val())) == false) {
                        $(".notice_erro_1").text('名称不合法\n');
                        $('#name').focus();
                    } else {
                        $(".notice_erro_1").hide();
                    }
                }

            })

            // 判断身份证

            $("#id_card").blur(function () {
                if ($.trim($('#id_card').val()).length == 0) {
                    $(".notice_erro_2").text('身份证号码没有输入\n');
                    $('#id_card').focus();
                } else {
                    if (isCardNo($.trim($('#id_card').val())) == false) {
                        $(".notice_erro_2").text('身份证号不正确；\n');
                        $('#id_card').focus();
                    }
                    else {
                        $(".notice_erro_2").hide();
                    }
                }
            })

            //判断手机号

            $("#mobile").blur(function () {
                if ($.trim($('#mobile').val()).length == 0) {
                    $(".notice_erro_3").text('手机号没有输入\n');
                    $('#mobile').focus();
                } else {
                    if (isPhoneNo($.trim($('#mobile').val()) == false)) {
                        $(".notice_erro_3").text('手机号码不正确\n');
                        $('#mobile').focus();
                    } else {
                        $(".notice_erro_3").hide();
                    }
                }

            })
            var flag = false;
            $(".apply_now").click(function () {
                if (flag) return;
                flag = true;
                if ($("#name")[0].value == "" || $("#name")[0].value == undefined) {
                    toastr.error("姓名不能为空");
                    return;
                }

                if ($("#mobile")[0].value == "" || $("#mobile")[0].value == undefined) {
                    toastr.error("手机号码不能为空");
                    return;
                }

                if ($("#id_card")[0].value == "" || $("#id_card")[0].value == undefined) {
                    toastr.error("身份证号不能为空");
                    return;
                }

                var query = {
                    name: $("#name")[0].value,
                    mobile: $("#mobile")[0].value,
                    id_card: $("#id_card")[0].value,
                    card_channel_id: $("#card_channel_id")[0].value
                };
                $.ajax({
                    url: '/card/SaveProposerInfo', type: "post", data: query,
                    success: function (response) {
                        if (response.result_code == 1000) {
                            toastr.success(response.data);
                            $(".apply_now").unbind();
                            setTimeout("window.location.href='/card/FastCard'", 1000);
                        } else {
                            toastr.error("申请失败");
                        }
                        flag = false;
                    }
                });
            })

        })
    </script>
}
